package com.yazi.mxz.common.db.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.yazi.mxz.common.db.dao.StorePromoteDao;
import com.yazi.mxz.common.entity.beans.Store;
import com.yazi.mxz.common.entity.beans.StorePromote;

import com.myframework.smhj.common.tool.DateUtil;
import com.myframework.smhj.hibernate.dao.BasicDao;

@Repository("storePromoteDao")
public class StorePromoteDaoImpl extends BasicDao<StorePromote> implements StorePromoteDao {


	public StorePromoteDaoImpl() {
		super(StorePromote.class);
	}

	@Override
	public Criteria getExample(StorePromote sp, String searchWord) {
		Criteria c = super.getExample(sp, searchWord);
		if (null != sp) {
			Store store = sp.getStore();
			if (null != store) {
				if (null != store.getStoreId()) {
					c.add(Restrictions.eq("store.storeId", store.getStoreId()));
				} else {
					// ...other Store's fields search
				}
			}
			// ...other StorePromote's fields search
		}
		// ...searchWord search
		return c;
	}
	

	@Override
	public int endByTime() {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("nowTime", DateUtil.getTimeStamp());
		return executeUpdate("endByTimeHql", param);
	}

	@Override
	public int startByTime() {
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("nowTime", DateUtil.getTimeStamp());
		return executeUpdate("startByTimeHql", param);
	}

	@Override
	public StorePromote oneNextStart() {
		return unique("oneNextStartHql", null);
	}

	@Override
	public StorePromote oneNextEnd() {
		return unique("oneNextEndHql", null);
	}


}
